package com.example.secondhandshop.ui.fragment;

import static android.content.Context.MODE_PRIVATE;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.example.secondhandshop.R;
import com.example.secondhandshop.ui.activity.LoginAcitivity;
import com.example.secondhandshop.ui.activity.MoneyActivity;
import com.example.secondhandshop.ui.activity.Person_trade;
import com.example.secondhandshop.ui.activity.HelpCenter;
import com.example.secondhandshop.ui.activity.Person_data;

public class PersonFragment extends Fragment {
    private TextView balanceTextView;
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_person, container, false);
        Button buyButton = view.findViewById(R.id.buyButton);
        Button sellButton = view.findViewById(R.id.sellButton);
        Button postButton = view.findViewById(R.id.postButton);
        Button editButton = view.findViewById(R.id.editButton);
        Button helpButton = view.findViewById(R.id.helpCenterButton);
        Button chevronRightButton1 = view.findViewById(R.id.chevronRightButton1);
        Button chevronRightButton = view.findViewById(R.id.chevronRightButton);
        balanceTextView = view.findViewById(R.id.balanceTextView);
        SharedPreferences sharedPreferences = requireActivity().getSharedPreferences(
                getResources().getString(R.string.sharepreferences_filename),
                Context.MODE_PRIVATE
        );
        int money = sharedPreferences.getInt("money", 0); // 默认值为0
        balanceTextView.setText("闲菜币：" + money);
        balanceTextView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), MoneyActivity.class);
                startActivity(intent);
            }
        });

        buyButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 跳转到已买页面
                Intent intent = new Intent(getActivity(), Person_trade.class);
                startActivity(intent);
            }
        });

        sellButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 跳转到已卖页面
                Intent intent = new Intent(getActivity(), Person_trade.class);
                startActivity(intent);
            }
        });

        postButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 跳转到已发布页面
                Intent intent = new Intent(getActivity(), Person_trade.class);
                startActivity(intent);
            }
        });

        editButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 跳转到已发布页面
                Intent intent = new Intent(getActivity(), Person_data.class);
                startActivity(intent);
            }
        });

        chevronRightButton1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 跳转到已发布页面
                Intent intent = new Intent(getActivity(), Person_data.class);
                startActivity(intent);
            }
        });

        helpButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 跳转到已发布页面
                Intent intent = new Intent(getActivity(), HelpCenter.class);
                startActivity(intent);
            }
        });

        chevronRightButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 跳转到已发布页面
                Intent intent = new Intent(getActivity(), HelpCenter.class);
                startActivity(intent);
            }
        });
        return view;
    }
}